<?php
	//function crop image theo cac chuan x345 x200 original, hien tai chi danh cho file jpg
	function cropImage($imgSrc,$thumbSize) {
		//getting the image dimensions
		list($width, $height) = getimagesize($imgSrc);

		//saving the image into memory (for manipulation with GD Library)
		$createTempImg = imagecreatefromjpeg($imgSrc);

		// calculating the part of the image to use for thumbnail
		if ($width > $height) {
		  $y = 0;
		  $x = ($width - $height) / 2;
		  $smallestSide = $height;
		} else {
		  $x = 0;
		  $y = ($height - $width) / 2;
		  $smallestSide = $width;
		}

		// copying the part into thumbnail
		$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
		imagecopyresampled($thumb, $createTempImg, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);

		//final output
		// header('Content-type: image/jpeg');
		imagejpeg($thumb, 'crop'.$thumbSize.'.jpg');
	}
?>